<?php

/**
 * Hooks of Html Helper helps create full admin page view.
 *
 * PHP versions 5
 * CAKEPHP versions 2.x
 * 
 * Green CMS - Content Management System and Framework Powerfull by Cakephp
 * Copyright 2012, GREEN GLOBAL CO., LTD (toancauxanh.vn)
 * 
 * CakePHP(tm) :  Rapid Development Framework (http://www.cakephp.org)
 * Copyright 2005-2011, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
 *
 * Licensed under The MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * @author        Technology Lab No.I <tech1@toancauxanh.vn>
 * @link          
 * @package       Green.Helper
 * @since         Green v 1.0
 * @license       MIT License (http://www.opensource.org/licenses/mit-license.php)
 */
App::uses('HtmlHelper', 'View/Helper');
App::uses('CakeEvent', 'Event');

class HookHtmlHelper extends HtmlHelper {

    /**
     * Adds a link to the breadcrumbs array.
     *
     * @param string $name Text for link
     * @param string $link URL for link (if empty it won't be a link)
     * @param mixed $options Link attributes e.g. array('id' => 'selected')
     * @return void
     *
     * @see HtmlHelper::addCrumb
     */
    public function addCrumb($name, $link = null, $options = null) {
        $this->getEventManager()->dispatch(new CakeEvent('Helper.Html.addCrumb', $this, array(&$name, &$link, &$options)));
        parent::addCrumb($name, $link, $options);
    }

    /**
     * Creates a link to an external resource and handles basic meta tags
     *
     * @param string $type The title of the external resource
     * @param mixed $url The address of the external resource or string for content attribute
     * @param array $options Other attributes for the generated tag. If the type attribute is html,
     *    rss, atom, or icon, the mime-type is returned.
     * @return string A completed `<link />` element.
     * 
     * @see HtmlHelper::meta
     */
    public function meta($type, $url = null, $options = array()) {
        $this->getEventManager()->dispatch(new CakeEvent('Helper.Html.meta', $this, array(&$type, &$url, &$options)));
        return parent::meta($type, $url, $options);
    }

    /**
     * Returns a charset META-tag.
     *
     * @param string $charset The character set to be used in the meta tag. If empty,
     *  The current response chartset value will be used. Example: "utf-8".
     * @return string A meta tag containing the specified character set.
     * 
     * @see HtmlHelper::charset
     */
    public function charset($charset = null) {
        $this->getEventManager()->dispatch(new CakeEvent('Helper.Html.charset', $this, array(&$charset)));
        if (empty($charset)) {
            $charset = $this->_View->response->charset();
        }
        return parent::charset($charset);
    }

    /**
     * Creates an HTML link.
     *
     * @param string $title The content to be wrapped by <a> tags.
     * @param mixed $url Cake-relative URL or array of URL parameters, or external URL (starts with http://)
     * @param array $options Array of HTML attributes.
     * @param string $confirmMessage JavaScript confirmation message.
     * @return string An `<a />` element.
     *  
     * @see HtmlHelper::link
     */
    public function link($title, $url = null, $options = array(), $confirmMessage = false) {
        $this->getEventManager()->dispatch(new CakeEvent('Helper.Html.link', $this, array(&$title, &$url, &$options, &$confirmMessage)));
        return parent::link($title, $url, $options, $confirmMessage);
    }

    /**
     * Creates a link element for CSS stylesheets.
     *
     * @param mixed $path The name of a CSS style sheet or an array containing names of
     *   CSS stylesheets. If `$path` is prefixed with '/', the path will be relative to the webroot
     *   of your application. Otherwise, the path will be relative to your CSS path, usually webroot/css.
     * @param string $rel Rel attribute. Defaults to "stylesheet". If equal to 'import' the stylesheet will be imported.
     * @param array $options Array of HTML attributes.
     * @return string CSS <link /> or <style /> tag, depending on the type of link.
     * 
     * @see HtmlHelper::css
     */
    public function css($path, $rel = null, $options = array()) {
        $this->getEventManager()->dispatch(new CakeEvent('Helper.Html.css', $this, array(&$path, &$rel, &$options)));
        return parent::css($path, $rel, $options);
    }

    /**
     * Returns one or many `<script>` tags depending on the number of scripts given.
     *
     * If the filename is prefixed with "/", the path will be relative to the base path of your
     * application.  Otherwise, the path will be relative to your JavaScript path, usually webroot/js.
     *
     * @param mixed $url String or array of javascript files to include
     * @param mixed $options Array of options, and html attributes see above. If boolean sets $options['inline'] = value
     * @return mixed String of `<script />` tags or null if $inline is false or if $once is true and the file has been
     *   included before.
     * 
     * @see HtmlHelper::script
     */
    public function script($url, $options = array()) {
        $this->getEventManager()->dispatch(new CakeEvent('Helper.Html.script', $this, array(&$url, &$options)));
        return parent::script($url, $options);
    }

    /**
     * Wrap $script in a script tag.
     *
     * @param string $script The script to wrap
     * @param array $options The options to use. Options not listed above will be
     *    treated as HTML attributes.
     * @return mixed string or null depending on the value of `$options['block']`
     * 
     * @see HtmlHelper::scriptBlock
     */
    public function scriptBlock($script, $options = array()) {
        $this->getEventManager()->dispatch(new CakeEvent('Helper.Html.scriptBlock', $this, array(&$script, &$options)));
        return parent::scriptBlock($script, $options);
    }

    /**
     * Begin a script block that captures output until HtmlHelper::scriptEnd()
     * is called. This capturing block will capture all output between the methods
     * and create a scriptBlock from it.
     *
     * @param array $options Options for the code block.
     * @return void
     * 
     * @see HtmlHelper::scriptStart
     */
    public function scriptStart($options = array()) {
        $this->getEventManager()->dispatch(new CakeEvent('Helper.Html.scriptStart', $this, array(&$options)));
        return parent::scriptStart($options);
    }

    /**
     * End a Buffered section of Javascript capturing.
     * Generates a script tag inline or in `$scripts_for_layout` depending on the settings
     * used when the scriptBlock was started
     *
     * @return mixed depending on the settings of scriptStart() either a script tag or null
     * 
     * @see HtmlHelper::scriptEnd
     */
    public function scriptEnd() {
        $this->getEventManager()->dispatch(new CakeEvent('Helper.Html.scriptEnd', $this));
        return parent::scriptEnd();
    }

    /**
     * Builds CSS style data from an array of CSS properties
     *
     * @param array $data Style data array, keys will be used as property names, values as property values.
     * @param boolean $oneline Whether or not the style block should be displayed on one line.
     * @return string CSS styling data
     * 
     * @see HtmlHelper::style
     */
    public function style($data, $oneline = true) {
        $this->getEventManager()->dispatch(new CakeEvent('Helper.Html.style', $this, array(&$data, &$oneline)));
        return parent::style($data, $oneline);
    }

    /**
     * Returns the breadcrumb trail as a sequence of &raquo;-separated links.
     *
     * @param string $separator Text to separate crumbs.
     * @param mixed $startText This will be the first crumb, if false it defaults to first crumb in array. Can
     *   also be an array, see above for details.
     * @return string Composed bread crumbs
     * 
     * @see HtmlHelper::getCrumbs
     */
    public function getCrumbs($separator = '&raquo;', $startText = false) {
        $this->getEventManager()->dispatch(new CakeEvent('Helper.Html.getCrumbs', $this, array(&$separator, &$startText)));
        return parent::getCrumbs($separator, $startText);
    }

    /**
     * Returns breadcrumbs as a (x)html list
     *
     * This method uses HtmlHelper::tag() to generate list and its elements. Works
     * similar to HtmlHelper::getCrumbs(), so it uses options which every
     * crumb was added with.
     *
     * @param array $options Array of html attributes to apply to the generated list elements.
     * @param mixed $startText This will be the first crumb, if false it defaults to first crumb in array. Can
     *   also be an array, see `HtmlHelper::getCrumbs` for details.
     * @return string breadcrumbs html list
     * 
     * @see HtmlHelper::getCrumbList
     */
    public function getCrumbList($options = array(), $startText = false) {
        $this->getEventManager()->dispatch(new CakeEvent('Helper.Html.getCrumbList', $this, array(&$options, &$startText)));
        return parent::getCrumbList($options, $startText);
    }

    /**
     * Creates a formatted IMG element.
     *
     * This method will set an empty alt attribute if one is not supplied.
     *
     * @param string $path Path to the image file, relative to the app/webroot/img/ directory.
     * @param array $options Array of HTML attributes.  See above for special options.
     * @return string completed img tag
     * 
     * @see HtmlHelper::image
     */
    public function image($path, $options = array()) {
        $this->getEventManager()->dispatch(new CakeEvent('Helper.Html.image', $this, array(&$path, &$options)));
        return parent::image($path, $options);
    }

    /**
     * Returns a row of formatted and named TABLE headers.
     *
     * @param array $names Array of tablenames.
     * @param array $trOptions HTML options for TR elements.
     * @param array $thOptions HTML options for TH elements.
     * @return string Completed table headers
     * 
     * @see HtmlHelper::tableHeaders
     */
    public function tableHeaders($names, $trOptions = null, $thOptions = null) {
        $this->getEventManager()->dispatch(new CakeEvent('Helper.Html.tableHeaders', $this, array(&$names, &$trOptions, $thOptions)));
        return parent::tableHeaders($names, $trOptions, $thOptions);
    }

    /**
     * Returns a formatted string of table rows (TR's with TD's in them).
     *
     * @param array $data Array of table data
     * @param array $oddTrOptions HTML options for odd TR elements if true useCount is used
     * @param array $evenTrOptions HTML options for even TR elements
     * @param boolean $useCount adds class "column-$i"
     * @param boolean $continueOddEven If false, will use a non-static $count variable,
     *    so that the odd/even count is reset to zero just for that call.
     * @return string Formatted HTML
     * 
     * @see HtmlHelper::tableCells
     */
    public function tableCells($data, $oddTrOptions = null, $evenTrOptions = null, $useCount = false, $continueOddEven = true) {
        $this->getEventManager()->dispatch(new CakeEvent('Helper.Html.tableCells', $this, array(&$data, &$oddTrOptions, &$evenTrOptions, &$useCount, &$continueOddEven)));
        return parent::tableCells($data, $oddTrOptions, $evenTrOptions, $useCount, $continueOddEven);
    }

    /**
     * Returns an audio/video element
     *
     * @param string|array $path Path to the video file, relative to the webroot/{$options['pathPrefix']} directory.
     *  Or an array where each item itself can be a path string or an associate array containing keys `src` and `type`
     * @param array $options Array of HTML attributes, and special options above.
     * @return string Generated media element
     * 
     * @see HtmlHelper::media
     */
    public function media($path, $options = array()) {
        $this->getEventManager()->dispatch(new CakeEvent('Helper.Html.media', $this, array(&$path, &$options)));
        return parent::media($path, $options);
    }

    /**
     * Build a nested list (UL/OL) out of an associative array.
     *
     * @param array $list Set of elements to list
     * @param array $options Additional HTML attributes of the list (ol/ul) tag or if ul/ol use that as tag
     * @param array $itemOptions Additional HTML attributes of the list item (LI) tag
     * @param string $tag Type of list tag to use (ol/ul)
     * @return string The nested list
     * 
     * @see HtmlHelper::nestedList
     */
    public function nestedList($list, $options = array(), $itemOptions = array(), $tag = 'ul') {
        $this->getEventManager()->dispatch(new CakeEvent('Helper.Html.nestedList', $this, array(&$list, &$options, &$itemOptions, &$tag)));
        return parent::nestedList($list, $options, $itemOptions, $tag);
    }

    /**
     * Load Html tag configuration.
     *
     * Loads a file from APP/Config that contains tag data.  By default the file is expected
     * to be compatible with PhpReader:
     *
     * @param mixed $configFile String with the config file (load using PhpReader) or an array with file and reader name
     * @param string $path Path with config file
     * @return mixed False to error or loaded configs
     * @throws ConfigureException
     * 
     * @see HtmlHelper::loadConfig
     */
    public function loadConfig($configFile, $path = null) {
        $this->getEventManager()->dispatch(new CakeEvent('Helper.Html.loadConfig', $this, array(&$configFile, &$path)));
        return parent::loadConfig($configFile, $path);
    }

}